package com.metagurukul.metaspace.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.metagurukul.metaspace.validator.Validator;

/**
 * @author ritesh
 *
 */
public class SignupForm extends ActionForm{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String emailId;
	public SignupForm() {
		super();
	}
	
	

	/**
	 * @return emailId of type String
	 */
	public String getEmailId() {
		return emailId;
	}



	/**
	 * @param emailId of type String
	 */
	public void setEmailId(String emailId) {
		this.emailId = emailId;
	}



	/* (non-Javadoc)
	 * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		Validator validator = new Validator();
		ActionErrors errors = new ActionErrors();
		if (emailId == null || emailId.equals("") || !validator.validateEmail(emailId)){
			errors.add("emailId", new ActionMessage("error.emailId.invalid"));
		}
		return errors;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		emailId = null;
	}
}
